home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-01
/
wlib11_2.zip
/
EXAMPLES.EXE
/
EXAM79.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-03-13
|
3KB
|
111 lines
#include <stdio.h>
#include <string.h>
#include "window.h"
#define NORM CREATE_VIDEO_ATTRIBUTE(black,white)
/* define filename characters */
#define FILENAMECHARS "25[A-Za-z0-9!@#$%/^&()+=_/-{}/[/]`~/.\\:]"
VWPOINTER vw; /* virtual window pointer */
WPOINTER w; /* Window pointer */
char filename[26];
FILE *infile; /* input file handle */
main()
{
unsigned int i,j,row,col;
WindowInitializeSystem();
WindowSaveInitial(0);
/* set up a Type 0 virtual window */
vw = VirtualInitialize(NOATTRIBUTE, /* virtual window type number */
200, /* Number of rows */
80, /* Number of cols */
0); /* Attribute */
/* set up viewport window */
w = WindowInitialize(BORDER,1,1,78,12,NORM,NORM,SINGLEBOX);
WindowOpen(w);
WindowDisplay(w,1,NOEFFECT);
/* read a file name */
read_file();
/* display file in viewport */
WindowAssignToVirtual(w,vw,1,1); /* Assign viewport to virtual window */
row = col = 1;
flush_keyboard_flag = TRUE; /* Set keyboard flush to TRUE */
while (1)
{
switch (GET_KEY()) /* Keep getting keys until ESCAPE key is hit */
{
case UARROW: /* Move viewport up 1 line */
if (row > 1)
WindowPositionViewport(w,--row,col);
break;
case DARROW: /* Move viewport down 1 line */
if (row < 189)
WindowPositionViewport(w,++row,col);
break;
case LARROW: /* Move viewport left 1 line */
if (col > 1)
WindowPositionViewport(w,row,--col);
break;
case RARROW: /* Move viewport right 1 line */
if (col < 69)
WindowPositionViewport(w,row,++col);
break;
case ESC: /* End program */
close_all();
break;
}
}
}
read_file() /* Gets a filename and displays it in the window */
{
int ch;
unsigned r = 1, c = 1;
filename[0] = 0;
WindowWriteString(w,"Please enter a file name: ",1,1);
WindowGetString(w,1,27,filename,'_',0,40,0,FILENAMECHARS);
if ((infile = fopen(filename,"r")) == NULL)
{
WindowMoveCursor(w,3,1);
WindowPrintf(w,"File name %s does not exist\nPress a key to continue",
filename);
GET_KEY();
close_all();
}
else
while(1) /* Read characters into virtual window */
{
ch = fgetc(infile);
if (feof(infile))
break;
if (ch != '\n')
VirtualWriteRepeatCharacter(vw,ch,r,c++,1);
else
{
r++;
c=1;
}
}
fclose(infile);
}
close_all()
{
WindowClose(w,NOEFFECT);
exit(0);
}